﻿using System;

namespace SoftwareConsulting.BI11.NumericalMethods.Statistics
{
    /// <summary>
    /// Класс описательной статистики: среднее отклонение ADev
    /// </summary>
    public class DescriptiveStatisticsADev
    {
        private double _result;
        /// <summary>
        /// Конструктор класса
        /// </summary>
        /// <param name="sample">выборка</param>
        /// <param name="sampleSize">размер выборки</param>
        public DescriptiveStatisticsADev(double[] sample,int sampleSize)
        {
            _result = 0;            
            double mean = 0;
            double adev = 0;
            if (sampleSize <= 0)
                return;            
            //среднее
            for (int i = 0; i <= sampleSize - 1; i++)
            {
                mean = mean + sample[i];
            }
            mean = mean / sampleSize;
            //ADev
            for (int i = 0; i <= sampleSize - 1; i++)
            {
                adev = adev + Math.Abs(sample[i] - mean);
            }
            adev = adev / sampleSize;
            _result = adev;
        }

        /// <summary>
        /// Возвращает решение
        /// </summary>        
        public double GetSolution()
        {
            return _result;
        }
    }
}
